from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-07 14:06:14.999743
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 07, Feb, 2022
Time: 14:06:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0136
Nobs: 560.000 HQIC: -48.4376
Log likelihood: 6577.12 FPE: 7.01276e-22
AIC: -48.7092 Det(Omega_mle): 5.98009e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351427 0.069198 5.079 0.000
L1.Burgenland 0.106226 0.042077 2.525 0.012
L1.Kärnten -0.110654 0.021859 -5.062 0.000
L1.Niederösterreich 0.193254 0.087418 2.211 0.027
L1.Oberösterreich 0.131990 0.086868 1.519 0.129
L1.Salzburg 0.254373 0.044499 5.716 0.000
L1.Steiermark 0.034638 0.058645 0.591 0.555
L1.Tirol 0.099391 0.047353 2.099 0.036
L1.Vorarlberg -0.070889 0.041857 -1.694 0.090
L1.Wien 0.017654 0.077293 0.228 0.819
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055307 0.149747 0.369 0.712
L1.Burgenland -0.041041 0.091055 -0.451 0.652
L1.Kärnten 0.040971 0.047304 0.866 0.386
L1.Niederösterreich -0.197544 0.189174 -1.044 0.296
L1.Oberösterreich 0.454882 0.187985 2.420 0.016
L1.Salzburg 0.283261 0.096298 2.942 0.003
L1.Steiermark 0.113987 0.126908 0.898 0.369
L1.Tirol 0.305545 0.102472 2.982 0.003
L1.Vorarlberg 0.022554 0.090580 0.249 0.803
L1.Wien -0.028190 0.167264 -0.169 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193491 0.035349 5.474 0.000
L1.Burgenland 0.088838 0.021494 4.133 0.000
L1.Kärnten -0.007443 0.011166 -0.667 0.505
L1.Niederösterreich 0.237075 0.044657 5.309 0.000
L1.Oberösterreich 0.169600 0.044376 3.822 0.000
L1.Salzburg 0.039024 0.022732 1.717 0.086
L1.Steiermark 0.025170 0.029958 0.840 0.401
L1.Tirol 0.081483 0.024190 3.368 0.001
L1.Vorarlberg 0.054923 0.021382 2.569 0.010
L1.Wien 0.119652 0.039484 3.030 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120099 0.035343 3.398 0.001
L1.Burgenland 0.043486 0.021491 2.023 0.043
L1.Kärnten -0.013614 0.011165 -1.219 0.223
L1.Niederösterreich 0.168914 0.044649 3.783 0.000
L1.Oberösterreich 0.334955 0.044368 7.550 0.000
L1.Salzburg 0.099695 0.022728 4.386 0.000
L1.Steiermark 0.110092 0.029953 3.676 0.000
L1.Tirol 0.090698 0.024185 3.750 0.000
L1.Vorarlberg 0.061210 0.021379 2.863 0.004
L1.Wien -0.015770 0.039477 -0.399 0.690
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127398 0.066594 1.913 0.056
L1.Burgenland -0.048660 0.040493 -1.202 0.229
L1.Kärnten -0.045471 0.021036 -2.162 0.031
L1.Niederösterreich 0.137373 0.084128 1.633 0.102
L1.Oberösterreich 0.165964 0.083598 1.985 0.047
L1.Salzburg 0.284601 0.042824 6.646 0.000
L1.Steiermark 0.057724 0.056437 1.023 0.306
L1.Tirol 0.156233 0.045570 3.428 0.001
L1.Vorarlberg 0.094693 0.040282 2.351 0.019
L1.Wien 0.073479 0.074384 0.988 0.323
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081153 0.051974 1.561 0.118
L1.Burgenland 0.024399 0.031603 0.772 0.440
L1.Kärnten 0.053353 0.016418 3.250 0.001
L1.Niederösterreich 0.191418 0.065659 2.915 0.004
L1.Oberösterreich 0.331678 0.065246 5.084 0.000
L1.Salzburg 0.032928 0.033423 0.985 0.325
L1.Steiermark 0.004296 0.044047 0.098 0.922
L1.Tirol 0.119651 0.035566 3.364 0.001
L1.Vorarlberg 0.066061 0.031439 2.101 0.036
L1.Wien 0.097093 0.058054 1.672 0.094
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174237 0.062752 2.777 0.005
L1.Burgenland 0.002882 0.038157 0.076 0.940
L1.Kärnten -0.065656 0.019823 -3.312 0.001
L1.Niederösterreich -0.113437 0.079274 -1.431 0.152
L1.Oberösterreich 0.215069 0.078776 2.730 0.006
L1.Salzburg 0.053514 0.040354 1.326 0.185
L1.Steiermark 0.249442 0.053181 4.690 0.000
L1.Tirol 0.498774 0.042941 11.615 0.000
L1.Vorarlberg 0.065321 0.037958 1.721 0.085
L1.Wien -0.076666 0.070093 -1.094 0.274
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158241 0.069490 2.277 0.023
L1.Burgenland -0.005265 0.042254 -0.125 0.901
L1.Kärnten 0.061550 0.021951 2.804 0.005
L1.Niederösterreich 0.172108 0.087786 1.961 0.050
L1.Oberösterreich -0.064253 0.087234 -0.737 0.461
L1.Salzburg 0.205834 0.044687 4.606 0.000
L1.Steiermark 0.139486 0.058891 2.369 0.018
L1.Tirol 0.057778 0.047552 1.215 0.224
L1.Vorarlberg 0.144056 0.042033 3.427 0.001
L1.Wien 0.133685 0.077619 1.722 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394697 0.040629 9.715 0.000
L1.Burgenland -0.003426 0.024705 -0.139 0.890
L1.Kärnten -0.021016 0.012834 -1.637 0.102
L1.Niederösterreich 0.198588 0.051327 3.869 0.000
L1.Oberösterreich 0.237987 0.051004 4.666 0.000
L1.Salzburg 0.034586 0.026127 1.324 0.186
L1.Steiermark -0.018718 0.034433 -0.544 0.587
L1.Tirol 0.088840 0.027803 3.195 0.001
L1.Vorarlberg 0.052401 0.024576 2.132 0.033
L1.Wien 0.039297 0.045382 0.866 0.387
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035265 0.104632 0.168771 0.134332 0.095844 0.081158 0.030528 0.212543
Kärnten 0.035265 1.000000 -0.024838 0.132679 0.046690 0.086130 0.444302 -0.068667 0.092111
Niederösterreich 0.104632 -0.024838 1.000000 0.308755 0.123732 0.267866 0.065176 0.156063 0.280343
Oberösterreich 0.168771 0.132679 0.308755 1.000000 0.216058 0.294335 0.170030 0.134378 0.236452
Salzburg 0.134332 0.046690 0.123732 0.216058 1.000000 0.124830 0.090110 0.103975 0.128363
Steiermark 0.095844 0.086130 0.267866 0.294335 0.124830 1.000000 0.134327 0.106298 0.029382
Tirol 0.081158 0.444302 0.065176 0.170030 0.090110 0.134327 1.000000 0.063813 0.152240
Vorarlberg 0.030528 -0.068667 0.156063 0.134378 0.103975 0.106298 0.063813 1.000000 -0.002832
Wien 0.212543 0.092111 0.280343 0.236452 0.128363 0.029382 0.152240 -0.002832 1.000000